package cn.itcast.crm.dao;

import cn.itcast.crm.domain.Customer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface CustomerRepository extends JpaRepository<Customer, Integer>, JpaSpecificationExecutor<Customer> {

    List<Customer> findByFixedAreaIdIsNull();

    List<Customer> findByFixedAreaId(String fixedAreaId);

    @Query("update Customer set fixedAreaId =?2 where  id= ?1")
    @Modifying
    void updateFixedAreaId(Integer id, String fixedAreaId);

    @Query("update Customer set fixedAreaId =null where  fixedAreaId= ?1")
    @Modifying
    void clearFixedAreaId(String fixedAreaId);
}
